﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.IO;

namespace weiqijiance.联网通信协议
{
    public class ReturnObject
    {

        public string StationCode { get; set; }

        public string SceneCode { get; set; }

        public string InspectionMethod { get; set; }

        public string VLPN { get; set; }

        public string VLPNColor { get; set; }

        public string VIN { get; set; }

        public string StartTime { get; set; }

        public string EndTime { get; set; }
    }
     public class socketyunjing
     {
         Thread threadRec = null;
         Socket socketClient = null;
         public string strRecMsg = "";
         public void connect(string sip, int sport)
         {
             IPAddress address = IPAddress.Parse(sip);
             IPEndPoint endport = new IPEndPoint(address, sport);
             socketClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
             socketClient.Connect(endport);

             threadRec = new Thread(RecMsg);
             threadRec.IsBackground = true;
             threadRec.Start();
         }
         void RecMsg()
         {
             while (true)
             {
                 byte[] arrMsgRec = new byte[1024 * 1024 * 2];
                 int length = socketClient.Receive(arrMsgRec);
                 strRecMsg += System.Text.Encoding.GetEncoding("GB2312").GetString(arrMsgRec, 0, length);
                 if (strRecMsg.Length > 0)
                 {
                     string ssss = strRecMsg;
                 }
                 //ShowMsg(strMsgRec);
             }
         }

         public void sendsocket(string strMsg)
         {
             byte[] arrMsg = System.Text.Encoding.GetEncoding("GB2312").GetBytes(strMsg);
             //byte[] arrMsgSend = new byte[arrMsg.Length];
             //// 添加标识位，0代表发送的是文字
             //arrMsgSend[0] = 0;
             //Buffer.BlockCopy(arrMsg, 0, arrMsgSend, 1, arrMsg.Length);
             socketClient.Send(arrMsg);

         }
    }
}
